#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 25;

int n, ans;
string s[N];
int st[N];

void dfs(string x, int y)
{
    st[y] ++ ;
    int len = x.size();
    ans = max(ans, len);
    string t;
    for (int i = 0; i < n; i ++ )
        for (int j = len - 1, k = 1; j > 0 && k < s[i].size(); j --, k ++ )
            if (st[i] < 2 && x.substr(j) == s[i].substr(0, k))
            {
                t = x.substr(0, len - k) + s[i];
                dfs(t, i);
            }
    st[y] -- ;
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i ++ )
        cin >> s[i];
    
    string str;
    cin >> str;
    str = " " + str;
    dfs(str, n);
    cout << ans - 1 << endl;
    return 0;
}
